package com.huaqin.punan.auroreceive;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class SmsReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context arg0, Intent arg1) {
		
		String textmsg = "";
		
		Bundle bundle = arg1.getExtras();
		Object messages[] = (Object[]) bundle.get("pdus");
		SmsMessage smsMessage[] = new SmsMessage[messages.length];
		for (int n = 0; n < messages.length; n++)
		{
			smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
		}
		
		textmsg = smsMessage[0].getMessageBody();
		
		Toast.makeText(arg0, "Received sms:" + textmsg, Toast.LENGTH_SHORT).show();
		
		abortBroadcast();
	}

}
